// pages/brand/brand.js
var app = getApp()  
var timer
Page({

  /**
   * 页面的初始数据
   */
  data: {
    letter_list: [
      "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z"
    ],
    brand_list: [],
    scrollTop: 0,
    show_letter: false,
    scroll_top:0,
    letter:'',
    showmodal:false
  },
  scroll_brand: function (e) {
    var id = e.currentTarget.id
    var that = this
    var letter = e.currentTarget.dataset.letter
    this.show_modal(letter)
    wx.createSelectorQuery().select('.letter_brand').scrollOffset(function (res) {
      var pagescrollTop =  res.scrollTop  // 节点的竖直滚动位置
      wx.createSelectorQuery().select('#brand_' + id).boundingClientRect(function (rect) {
        that.setData({
          scroll_top: rect.top + pagescrollTop
        })
      }).exec()
    }).exec()
  },
  show_modal:function(t){
    clearTimeout(timer)
    var that =this
    this.setData({
      letter: t,
      showmodal:true
    })
    timer = setTimeout(function(){
      that.setData({
        showmodal: false
      })
    },1000)
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.showLoading({
      title: '加载中',
    })
    wx.createSelectorQuery().select('#brand_0').boundingClientRect(function (rect) {
      that.setData({
        scrollTop: rect.top
      })
    }).exec()
    app.ajax({
      url:app.host + "/mall/brand",
      success:function(res){
        wx.hideLoading()
        that.setData({
          brand_list:res.data.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})